package com.yhn.bubblevideo.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.bubblevideo.admin.service.UserLikesService;
import com.yhn.bubblevideo.common.model.BaseResponse;
import com.yhn.bubblevideo.common.model.DeleteBatchRequest;
import com.yhn.bubblevideo.common.model.ResultUtils;
import com.yhn.bubblevideo.model.dto.req.common.DeleteRequest;
import com.yhn.bubblevideo.model.dto.req.userlikes.UserLikesAddRequestDTO;
import com.yhn.bubblevideo.model.dto.req.userlikes.UserLikesEditRequestDTO;
import com.yhn.bubblevideo.model.dto.req.userlikes.UserLikesQueryRequestDTO;
import com.yhn.bubblevideo.model.dto.resp.UserLikesRespDTO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * @author yhn
 * @version 1.0
 * @description
 * @date 2024/11/24 15:19
 */
@RestController
@RequestMapping("/user/likes")
public class UserLikesController {
    @Resource
    private UserLikesService userLikesService;

    /**
     * 列表,分页
     */

    @PostMapping("/list")
    @SaCheckLogin
    public BaseResponse<Page<UserLikesRespDTO>> listUserLikesPage(@RequestBody @Valid UserLikesQueryRequestDTO requestParam) {
        Page<UserLikesRespDTO> page = userLikesService.queryPage(requestParam);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    public BaseResponse<UserLikesRespDTO> getUserLikesInfoById(@PathVariable("id") Long id) {
        UserLikesRespDTO userLikes = userLikesService.getInfoById(id);
        return ResultUtils.success(userLikes);
    }


    /**
     * 保存
     */
    @PostMapping("/add")
    public BaseResponse<Long> saveUserLikes(@RequestBody @Valid UserLikesAddRequestDTO requestParam) {
        Long newId = userLikesService.saveUserLikes(requestParam);
        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateUserLikes(@RequestBody @Valid UserLikesEditRequestDTO requestParam) {
        boolean result = userLikesService.updateUserLikes(requestParam);
        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteUserLikes(@RequestBody DeleteRequest deleteRequest) {
        boolean result = userLikesService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    public BaseResponse<Boolean> deleteBatchUserLikess(@RequestBody DeleteBatchRequest deleteBatchRequest) {
        boolean result = userLikesService.deleteBatchByIds(deleteBatchRequest.getIds());
        return ResultUtils.success(result);
    }
}
